package com.ibo.htlivecamera.launcher;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.ibo.htlivecamera.R;

import java.util.ArrayList;
import java.util.List;

public class DeskTopGridViewBaseAdapter extends BaseAdapter {
 
    Context context;
    List<AppInfo> appInfos=new ArrayList<>();
 
    public DeskTopGridViewBaseAdapter(List<AppInfo> appInfos,Context context){
        this.appInfos=appInfos;
        this.context=context;
    }
 
    @Override
    public int getCount() {
        return appInfos.size();
    }
 
    @Override
    public Object getItem(int position) {
        return appInfos.get(position);
    }
 
    @Override
    public long getItemId(int position) {
        return position;
    }
 
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Holder holder=null;
        if (convertView==null){
            convertView = LayoutInflater.from(context).inflate(R.layout.desktop_gridview_item,parent,false);
            holder=new Holder();
            holder.ico=(ImageView) convertView.findViewById(R.id.iv);
            holder.Name=(TextView) convertView.findViewById(R.id.tv);
            convertView.setTag(holder);
        }else {
            holder= (Holder) convertView.getTag();
        }
 
        holder.ico.setImageDrawable(appInfos.get(position).getIco());
        holder.Name.setText(appInfos.get(position).getName());
 
        return convertView;
    }
 
 
    static class Holder{
        ImageView ico;
        TextView Name;
 
    }
}